# -*- coding: utf-8 -*-
from geraldo import Report, ReportBand, ObjectValue, ReportBand, landscape,\
        SystemField, BAND_WIDTH, Label, ReportGroup, SubReport


from reportlab.lib.units import cm
from reportlab.lib.pagesizes import A5
from reportlab.lib.enums import TA_CENTER, TA_RIGHT

class RelatorioMedicos(Report):
    title = 'Listagem de Médicos'
    print_if_empty = True
    page_size = landscape(A5)
    
    class band_detail(ReportBand):
        height = 0.7*cm #Espaço entre as linhas
        elements=(
                ObjectValue(attribute_name='id', count=4, left=0.5*cm), #Distância entre os objetos em uma mesma linha
                ObjectValue(attribute_name='nome', left=5*cm,width=10*cm), #width definir tamanho do nome no documento pdf
                ObjectValue(attribute_name='crm', left=12*cm),
                ObjectValue(attribute_name='datacriacao', left=1*cm,
                    get_value=lambda instance: instance.created_at.strftime('%d/%m/%Y')),
                )
    class band_page_header(ReportBand):
        height = 1.3*cm #Distância da linha superior do relatório
        elements = [
                SystemField(expression='%(report_title)s', top=0.1*cm, left=0, width=BAND_WIDTH,
                    style={'fontName': 'Helvetica-Bold', 'fontSize': 14, 'alignment': TA_CENTER}),
                Label(text="ID", top=0.8*cm, left=0.5*cm),
                Label(text=u"Data do Registro", top=0.8*cm, left=1*cm),
                Label(text="Nome do Médico", top=0.8*cm, left=5*cm),
                Label(text="Crm", top=0.8*cm, left=12*cm),
                SystemField(expression=u'Página %(page_number)d de %(page_count)d', top=0.1*cm,
                    width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
                ]
        borders = {'bottom': True}
    class band_page_footer(ReportBand):
        height = 0.5*cm
        elements = [
                Label(text='7vidas', top=0.1*cm),
                SystemField(expression=u'Impresso em: %(now:%d / %m / %Y)s às %(now:%H:%M)s', top=0.1*cm,
                    width=BAND_WIDTH, style={'alignment': TA_RIGHT}),
                ]
        borders = {'top': True}
        